package org.example;

import java.time.*;
import java.time.temporal.ChronoUnit;

public class DateDemo3 {
    public static void main(String[] args) {
        System.out.println("========1");
        //获取当前日期
        LocalDate nowDate = LocalDate.now();
        System.out.println(nowDate);

        //指定日期
        LocalDate Date1 = LocalDate.of(2020, 1, 1);
        System.out.println("指定日期" + Date1);
        //获取年
        int year = Date1.getYear();
        //获取月
        int month = Date1.getMonthValue();
        //获取日
        int day = Date1.getDayOfMonth();
        //withXxx()  修改  min 表示减小  plus表示增加
        LocalDate date = Date1.withYear(2025);
        System.out.println(date);

        //判断今天是否是个人生日
        LocalDate date2 = LocalDate.of(2020, 7, 15);
        LocalDate nowDate1 = LocalDate.now();

        MonthDay birthday = MonthDay.of(date2.getMonth(), date2.getDayOfMonth());
        MonthDay nowMd = MonthDay.of(nowDate1.getMonth(), nowDate1.getDayOfMonth());
        //MonthDay birthday=MonthDay.from(date2);
        //MonthDay nowMd=MonthDay.from(nowDate1);
        if (birthday.equals(nowMd)) {
            System.out.println("是你的生日");
        } else {
            System.out.println("不是你的生日");

        }
        //localTime类似
        System.out.println("=============3");
        LocalDate nowDate2=LocalDate.now();
        LocalDate date3=LocalDate.of(2025,11,12);
        LocalDateTime date4=LocalDateTime.of(2025,11,1,2,34,45);
        //Period  时间差
        Period p=Period.between(nowDate2,date3);
        System.out.println(p);
        System.out.println(p.getYears());
        System.out.println(p.getMonths());
        System.out.println(p.getDays());
        System.out.println("总共"+p.toTotalMonths() + "月");
        //Duration  时间差
        Duration d=Duration.between(nowDate2.atStartOfDay(),date4);
        System.out.println(d.toDays());
        System.out.println(d.toMinutes());
        System.out.println(d.toSeconds());
        System.out.println(d.toMillis());//毫秒
        System.out.println(d.toNanos());//纳秒
        //ChronoUnit  时间差
        long years=ChronoUnit.YEARS.between(nowDate2,date4);
        long days= ChronoUnit.DAYS.between(nowDate2,date4);
        long hours= ChronoUnit.HOURS.between(nowDate2.atStartOfDay(),date4);
        long minutes= ChronoUnit.MINUTES.between(nowDate2.atStartOfDay(),date4);
        long seconds= ChronoUnit.SECONDS.between(nowDate2.atStartOfDay(),date4);
        System.out.println(years);
        System.out.println(days);
        System.out.println(hours);
        System.out.println(minutes);
        System.out.println(seconds);

        System.out.println("=============4");
        //转化为二进制
        String str1=Integer.toBinaryString(100);
        System.out.println(str1);
        System.out.println("=============5");
        //转化为八进制
        String str2=Integer.toOctalString(100);
        System.out.println(str2);
        System.out.println("=============6");
        //转化为十六进制
        String str3=Integer.toHexString(100);
        System.out.println(str3);
        System.out.println("=============7");
        //将字符串
        //转化为int
        int i=Integer.parseInt("100");
        System.out.println(i);
        System.out.println("=============8");
        //转化为double
        double d1=Double.parseDouble("100");
        System.out.println(d1);
        System.out.println("=============9");
        //转化为float
        float f1=Float.parseFloat("100");
        System.out.println(f1);
        System.out.println("=============10");
        //转化为long
        long l1=Long.parseLong("100");
        System.out.println(l1);
        System.out.println("=============11");
        //转化为short
        short s1=Short.parseShort("100");
        System.out.println(s1);
        System.out.println("=============12");
        //转化为byte
        byte b1=Byte.parseByte("100");
        System.out.println(b1);
        System.out.println("=============13");
        //转化为char
        char c1='1';
        System.out.println(c1);
        System.out.println("=============14");
        //转化为boolean
        boolean b2=Boolean.parseBoolean("true");
        System.out.println(b2);
        System.out.println("=============15");
        //转化为String
        String str4=String.valueOf(100);
        System.out.println(str4);
        System.out.println("=============16");
        //转化为String
        String str5=String.valueOf(true);
        System.out.println(str5);
        System.out.println("=============17");
        //转化为String
        String str6=String.valueOf('1');
        System.out.println(str6);
        //Scanner s=new Scanner(System.in);
        //String str7=s.nextLine();
        //System.out.println(str7);
        //以后统一用s.nextLine()





    }
}
